package com.mailbox.mailbox.controller;

import com.mailbox.mailbox.service.MessageService;
import com.mailbox.mailbox.service.VisitorService;
import com.mailbox.mailbox.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
/**
 *
 * @author
 */
@Api(tags = "留言管理")
public class MessageController {

    @Resource
    MessageService messageService;



    @GetMapping("/Admin/findAllMessages")
    @ApiOperation("遍历所有的留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
    })
    public ResponseResult findAllMessages(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size){
        return messageService.findAllMessages(page,size);
    }

    @GetMapping("/Admin/findSuchMessages")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "startTime",value = "开始的时间(yyyy-MM-dd HH:mm:ss)", required = false),
            @ApiImplicitParam(name = "endTime",value = "结束的时间(yyyy-MM-dd HH:mm:ss)", required = false),
//            @ApiImplicitParam(name = "类型",value = "类型", required = false),
    })
    @ApiOperation("根据类型或者时间查询留言（类型为空，有时间代表根据时间查询；有类型，时间空，代表类型查询，都有代表根据两者一起查询）")
    public ResponseResult findSuchMessages(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size, String startTime,String endTime,String type){
        return messageService.findSuchMessages(page,size,type,startTime,endTime);
    }

    @GetMapping("/Admin/selectByPhone")
    @ApiOperation("根据电话查询留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "phone",value = "电话", required = true),
    })
    public ResponseResult selectByPhone(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size, String phone){
        return messageService.selectByPhone(page,size,phone);
    }

    @GetMapping("/Admin/selectByName")
    @ApiOperation("根据姓名查询留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "name",value = "姓名", required = true),
    })
    public ResponseResult selectByName(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size, String name){
        return messageService.selectByName(page,size,name);
    }

    @GetMapping("/Admin/selectByEmail")
    @ApiOperation("根据邮箱查询留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "email",value = "邮箱", required = true),
    })
    public ResponseResult selectByEmail(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size, String email){
        return messageService.selectByEmail(page,size,email);
    }

    @GetMapping("/Admin/selectByContent")
    @ApiOperation("根据内容查询留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "content",value = "内容", required = true),
    })
    public ResponseResult selectByContent(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size, String content){
        return messageService.selectByContent(page,size,content);
    }

    @DeleteMapping("/Admin/deleteMessages")
    @ApiOperation("批量删除留言（单个也可以）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "id集合", required = true),
    })
    public ResponseResult deleteMessages(String ids){
        return messageService.deleteMessages(ids);
    }

    @GetMapping("/Admin/findUnSee")
    @ApiOperation("查看各种类型的留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页数", required = false),
            @ApiImplicitParam(name = "size",value = "每页的多少", required = false),
            @ApiImplicitParam(name = "status",value = "状态（0未查看，1已回复，2未回复,3已公开,4未公开）", required = true),
    })
    public ResponseResult findUnSee(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "5") Integer size,Integer status){
        return messageService.findUnSee(page,size,status);
    }

    @GetMapping("/Admin/findUnSeeCounts")
    @ApiOperation("查看各种类型的留言的数目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status",value = "状态（0未查看，1已回复，2未回复,3已公开,4未公开）", required = true),
    })
    public ResponseResult findUnSeeCounts(Integer status){
        return messageService.findUnSeeCounts(status);
    }



    @GetMapping("/Admin/findOpenMessage")
    @ApiOperation("管理员查看公开的留言")
    public ResponseResult findOpenMessage(Integer pageNow,Integer pageSize){
        return messageService.findOpenMessage(pageNow,pageSize);
    }


    @GetMapping("/Admin/findNotOpenMessage")
    @ApiOperation("管理员查看未公开的留言")
    public ResponseResult findNotOpenMessage(Integer pageNow,Integer pageSize){
        return messageService.findNotOpenMessage(pageNow,pageSize);
    }

    @PutMapping("/Admin/openMessage")
    @ApiOperation("管理员公开留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageId",value = "信件id", required = true)
    })
    public ResponseResult openMessage(Integer messageId){
        return messageService.openMessage(messageId);
    }

    @PutMapping("/Admin/closeMessage")
    @ApiOperation("管理员关闭公开的留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "messageId",value = "信件id", required = true)
    })
    public ResponseResult closeMessage(Integer messageId){
        return messageService.closeMessage(messageId);
    }


}
